import apple from "../main"

/**
 * 校验手机号
 * @param phone
 * @returns {boolean}
 */
export function checkPhone(phone) {
  let reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
  if (phone == "" || phone == undefined) {
    apple.$vux.toast.text("手机号码不能为空", "middle");
    return false;
  }
  if (!reg.test(phone)) {
    apple.$vux.toast.text("手机号码格式错误", "middle");
    return false;
  }
  return true;
}

/**
 * 校验密码
 * @param pwd
 * @returns {boolean}
 */
export function checkPwd(pwd, type) {
  if (pwd == "" || pwd == undefined) {
    apple.$vux.toast.text("密码不能为空", "middle");
    return false;
  } else if (pwd.indexOf(" ") >= 0) {
    apple.$vux.toast.text("密码中不能有空格字符", "middle");
    return false;
  } else if ((/[\u4e00-\u9fa5]+/).test(pwd)) {
    apple.$vux.toast.text("密码不能包含中文", "middle");
    return false;
  }
  if (type == 2) {
    if (pwd.length < 6 || pwd.length > 16) {
      apple.$vux.toast.text("密码长度为6-16位", "middle");
      return false;
    }
  }

  return true;
}

/**
 * 校验验证码
 * @returns {boolean}
 */
export function checkCode(code) {
  let reg = /^[0-9]*$/;
  if (code == "" || code == undefined) {
    apple.$vux.toast.text("验证码不能为空", "middle");
    return false;
  } else if (!reg.test(code)) {
    apple.$vux.toast.text("验证码格式不正确", "middle");
    return false;
  }
  return true;
}


/**
 * 校验姓名
 * @param name
 * @returns {boolean}
 */
export function checkName(name) {//校验姓名
  let reg = /^[\u2E80-\u9FFF]+$/;
  if (name == undefined || name == "") {
    apple.$vux.toast.text("请输入您的姓名");
    return false;
  } else if (!reg.test(name)) {
    apple.$vux.toast.text("请输入您的中文姓名");
    return false;
  } else if (name.length > 6) {
    apple.$vux.toast.text("姓名最多5位");
    return false;
  }
  return true;
}

